-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Field::Select more flexible #1220
Conversation
spec/lib/fields/select_spec.rb
Outdated
expected.each do |inputs, o_key| | ||
it "`#{inputs.first}` and value `#{inputs.last}` returns output `#{o_key}`" do | ||
c_key, p_key = inputs | ||
field = select_with_options(persisted[p_key], collection: collections[c_key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [87/80]
spec/lib/fields/select_spec.rb
Outdated
} | ||
|
||
expected.each do |inputs, o_key| | ||
it "`#{inputs.first}` and value `#{inputs.last}` returns output `#{o_key}`" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [86/80]
spec/lib/fields/select_spec.rb
Outdated
[ :hash_sym, :integer ] => nil, | ||
[ :hash_nil, nil ] => :no_status, | ||
[ :hash_nil, :string ] => :approved, | ||
[ :hash_nil, :integer ] => nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :hash_sym, :string ] => :approved, | ||
[ :hash_sym, :integer ] => nil, | ||
[ :hash_nil, nil ] => :no_status, | ||
[ :hash_nil, :string ] => :approved, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :hash_sym, nil ] => nil, | ||
[ :hash_sym, :string ] => :approved, | ||
[ :hash_sym, :integer ] => nil, | ||
[ :hash_nil, nil ] => :no_status, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :arrays_sym, :integer ] => nil, | ||
[ :arrays_nil, :nil ] => :no_status, | ||
[ :arrays_nil, :string ] => :approved, | ||
[ :arrays_nil, :integer ] => nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :arrays_sym, :string ] => :approved, | ||
[ :arrays_sym, :integer ] => nil, | ||
[ :arrays_nil, :nil ] => :no_status, | ||
[ :arrays_nil, :string ] => :approved, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :arrays_sym, nil ] => nil, | ||
[ :arrays_sym, :string ] => :approved, | ||
[ :arrays_sym, :integer ] => nil, | ||
[ :arrays_nil, :nil ] => :no_status, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :arrays_str, :integer ] => nil, | ||
[ :arrays_sym, nil ] => nil, | ||
[ :arrays_sym, :string ] => :approved, | ||
[ :arrays_sym, :integer ] => nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
[ :arrays_str, :string ] => :approved, | ||
[ :arrays_str, :integer ] => nil, | ||
[ :arrays_sym, nil ] => nil, | ||
[ :arrays_sym, :string ] => :approved, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/SymbolArray: Use %i or %I for an array of symbols.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
spec/lib/fields/select_spec.rb
Outdated
|
||
describe "#label_data" do | ||
it "returns nil without options" do | ||
field = Administrate::Field::Select.new(:select, persisted[:string], :show) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [81/80]
spec/lib/fields/select_spec.rb
Outdated
|
||
expected.each do |in_key, out_key| | ||
it "`#{in_key}` returns collection `#{out_key}`" do | ||
field = select_with_options(persisted[:string], collection: collections[in_key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [90/80]
spec/lib/fields/select_spec.rb
Outdated
:arrays_nil => :arrays_nil, | ||
:hash_str => :arrays_str, | ||
:hash_sym => :arrays_sym, | ||
:hash_nil => :arrays_nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
spec/lib/fields/select_spec.rb
Outdated
:arrays_sym => :arrays_sym, | ||
:arrays_nil => :arrays_nil, | ||
:hash_str => :arrays_str, | ||
:hash_sym => :arrays_sym, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
spec/lib/fields/select_spec.rb
Outdated
:arrays_str => :arrays_str, | ||
:arrays_sym => :arrays_sym, | ||
:arrays_nil => :arrays_nil, | ||
:hash_str => :arrays_str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
spec/lib/fields/select_spec.rb
Outdated
arrays_nil: [ ['No status', nil], ['Approved!', 'approved'] ], | ||
hash_str: { 'Pending' => 'submitted', 'Approved!' => 'approved' }, | ||
hash_sym: { 'Pending' => :submitted, 'Approved!' => :approved }, | ||
hash_nil: { 'No status' => nil, 'Approved!' => 'approved' } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
spec/lib/fields/select_spec.rb
Outdated
arrays_sym: [ ['Pending', :submitted], ['Approved!', :approved] ], | ||
arrays_nil: [ ['No status', nil], ['Approved!', 'approved'] ], | ||
hash_str: { 'Pending' => 'submitted', 'Approved!' => 'approved' }, | ||
hash_sym: { 'Pending' => :submitted, 'Approved!' => :approved }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
spec/lib/fields/select_spec.rb
Outdated
arrays_str: [ ['Pending', 'submitted'], ['Approved!', 'approved'] ], | ||
arrays_sym: [ ['Pending', :submitted], ['Approved!', :approved] ], | ||
arrays_nil: [ ['No status', nil], ['Approved!', 'approved'] ], | ||
hash_str: { 'Pending' => 'submitted', 'Approved!' => 'approved' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
spec/lib/fields/select_spec.rb
Outdated
array_int: [1, 2, 3], | ||
arrays_str: [ ['Pending', 'submitted'], ['Approved!', 'approved'] ], | ||
arrays_sym: [ ['Pending', :submitted], ['Approved!', :approved] ], | ||
arrays_nil: [ ['No status', nil], ['Approved!', 'approved'] ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
spec/lib/fields/select_spec.rb
Outdated
empty: [], | ||
array_int: [1, 2, 3], | ||
arrays_str: [ ['Pending', 'submitted'], ['Approved!', 'approved'] ], | ||
arrays_sym: [ ['Pending', :submitted], ['Approved!', :approved] ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
spec/lib/fields/select_spec.rb
Outdated
array_int: [1,2,3], | ||
arrays_str: [["Pending","submitted"],["Approved!","approved"]], | ||
arrays_sym: [["Pending", :submitted],["Approved!",:approved]], | ||
arrays_nil: [["No status",nil],["Approved!","approved"]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAfterComma: Space missing after comma.
spec/lib/fields/select_spec.rb
Outdated
empty: [], | ||
array_int: [1,2,3], | ||
arrays_str: [["Pending","submitted"],["Approved!","approved"]], | ||
arrays_sym: [["Pending", :submitted],["Approved!",:approved]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAfterComma: Space missing after comma.
spec/lib/fields/select_spec.rb
Outdated
{ | ||
empty: [], | ||
array_int: [1,2,3], | ||
arrays_str: [["Pending","submitted"],["Approved!","approved"]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAfterComma: Space missing after comma.
spec/lib/fields/select_spec.rb
Outdated
let(:collections) do | ||
{ | ||
empty: [], | ||
array_int: [1,2,3], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/SpaceAfterComma: Space missing after comma.
lib/administrate/field/select.rb
Outdated
when NilClass | ||
nil | ||
when Array | ||
pair = collection.detect { |l,v| v.to_s == data.to_s } || [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lint/UnusedBlockArgument: Unused block argument - l. If it's necessary, use _ or _l as an argument name to indicate that it won't be used.
Layout/SpaceAfterComma: Space missing after comma.
Any word on this? It would be really useful to have. I feel like Administrate has so much potential and then stuff like this doesn't get merged. Can I do something to fix it and get it merged? I'd be happy to update the syntax if that's the issue here. |
Closed due to lack of activity. Additionally, I am not sure about overloading However this means that |
Field::Select
so we can set an array of arrays and a hash tocollection
option. This behavior would be more intuitive since it follows Rails form helper convention.Enum
field referred to Add search support for ActiveRecord::Enum columns #322 and Enum fields #533 so we don't have to create a Enum field as a custom or built-in field anymore.By default, it displays label data(e.g. "Pending") instead of raw persisted data(e.g. 1) on show/index page. Search feature would be an issue because users would want to search by label data but the system searches only by persisted data for the moment. However, that issue should be solved by another PR, not this one. Thank you for this awesome gem 😃
Basic usage:
=>
For Enum: